package com.zhanggm.springcloud.mongo.controller;

import com.alibaba.fastjson.JSON;
import com.zhanggm.springcloud.mongo.dao.LogRepository;
import com.zhanggm.springcloud.mongo.model.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.UUID;

@RestController
@RequestMapping("/mongo/")
public class LogController {


    @Autowired
    private LogRepository logRepository;

    @PostMapping("addLog")
    public boolean addLog(@RequestBody String logJsonData){
        Log log = JSON.parseObject(logJsonData, Log.class);
        log.setId(UUID.randomUUID().toString());
        log.setCreateTime(new Date());
        logRepository.save(log);
        return true;
    }
}
